package it.mozzicato.apkwizard.dto;

import java.util.*;

/**
 * @author Roberto Mozzicato
 *
 */
public class PublicResource extends BaseResource {
	private String id;
	private List<ValueResource> values = new LinkedList<ValueResource>();
	
	/**
	 * Costruttore
	 * @param type
	 * @param name
	 * @param id
	 */
	public PublicResource(ResourceTypes type, String name, String id) {
		super(type, name, null);
		
		this.id = id;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	@Override
	public ResourceStatus getStatus() {
		ResourceStatus ret = super.getStatus();
		
		if(ret == ResourceStatus.ORIGINAL) {
			for (ValueResource res : values) {
				if(!res.getValue().equals(res.getOriginalValue())) {
					return ResourceStatus.UPDATED;
				}
			}
		}
			
		return ret;
	}
	
	@Override
	public boolean equals(Object obj) {
		if(!(obj instanceof PublicResource))
			return false;
		
		PublicResource otherRes = (PublicResource) obj;
		return id==null && super.equals(obj) || id != null && id.equals(otherRes.id);
	}

	public void clearValues() {
		values.clear();
	}
	
	public void addValue(ValueResource res) {
		values.add(res);
	}
	
	public void removeValue(ValueResource res) {
		values.remove(res);
	}
}
